package com.wuzheng.wisgo.sanitation.cloud.repository.builder.transfer;

import com.wuzheng.wisgo.sanitation.framework.util.StringUtils;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author：hoipang
 * @date：Created in 2019-12-06
 * @description：构建sql
 * @modified By：
 * @version: 1.0
 */
public class TransferRouteBuilder {

    /**
     * 构建转运路线特定信息分页列表sql
     * @param name
     * @return
     */
    public String buildPageTransferRouteDTOsSql(String name){
        return new SQL(){
            {
                SELECT("DISTINCT t1.id, t2.customer_name AS deptName, t1.route_name AS routeName, t1.remark");
                SELECT("(SELECT COUNT(*) FROM ba_transfer_route_trash AS t3 WHERE t3.transfer_route_id= t1.id AND t3.de_flag = FALSE) AS trashNumber");
                FROM("ba_transfer_route AS t1");
                JOIN("san_user AS t2 ON t1.customer_id = t2.customer_id");
                WHERE(" t1.de_flag = FALSE");
                if(StringUtils.isNotBlank(name)){
                    WHERE("t1.route_name LIKE CONCAT('%', #{name}, '%')");
                }
            }
        }.toString();
    }
}
